﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using LuaInterface;
using ElementumForever.Interfaces;

namespace ElementumForever
{
    abstract class BaseActor : BaseEntity
    {
        List<IComponent> componentList;

        public BaseActor()
            : base()
        {
        }

        public override void OnCreat()
        {
            base.OnCreat();
            componentList = new List<IComponent>();
        }


        public override void OnUpdate(GameTime gameTime)
        {
            foreach (IComponent comp in componentList)
            {
                if (comp.Enable)
                    comp.OnUpdate(gameTime);
            }
        }

        public override void OnDraw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            foreach (IComponent comp in componentList)
            {
                if (comp.Enable)
                    comp.OnDraw(gameTime, spriteBatch);
            }
        }

        public void RegisterComponent(IComponent component)
        {
            if (!component.HasParent && !componentList.Contains(component))
            {
                componentList.Add(component);
                component.OnRegister(this);
            }


        }

        public void UnregisterComponent(IComponent component)
        {
            componentList.Remove(component);
            component.OnUnregister();
        }

        public override void Dispose()
        {
        }
    }
}
